import http from '@/utils/http';
import type {
  TLoginReq,
  TUserInfo,
  TRegisterReq,
  TUpdateUserReq,
  TRefreshToken,
  TRefreshTokenReq
} from './type';

export const login = (data: TLoginReq) =>
  http.post<TUserInfo>('/api/v1/login', data);

export const wxLogin = (code: string) =>
  http.get<string>('/api/v1/wechat/wxLogin', { code });

export const register = (data: TRegisterReq) =>
  http.post<{ id: number }>('/api/v1/user/register', data);

export const updateUserInfo = (data: TUpdateUserReq) =>
  http.post<TUserInfo>('/api/v1/user/updateUser', data);

export const refreshToken = (data: TRefreshTokenReq) =>
  http.post<TRefreshToken>('/api/v1/refreshToken', data);

export const getUserInfoById = (id: number) =>
  http.get<TUserInfo>(`/api/v1/user/findUserById?id=${id}`);

export const getEmailCode = (email: string) =>
  http.post<string>('/api/v1/sendEmail', { email });
